Test Series - Data Structure

Test Number 33/115

Q: What is a bit array?
A. Data structure for representing arrays of records
B. Data structure that compactly stores bits
C. An array in which most of the elements have the same value
D. Array in which elements are not present in continuous locations
Solution: It compactly stores bits and exploits bit-level parallelism.
Q: Which of the following bitwise operations will you use to set a particular bit to 1?
A. OR
B. AND
C. XOR
D. NOR
Solution: 1 OR 1 = 1, 0 OR 1 = 1, any bit OR’ed with 1 gives 1.
Q: Which of the following bitwise operations will you use to set a particular bit to 0?
A. OR
B. AND
C. XOR
D. NAND
Solution: 1 AND 0 = 0, 0 AND 0 = 0, any bit AND with 0 gives 0.
Q: Which of the following bitwise operations will you use to toggle a particular bit?
A. OR
B. AND
C. XOR
D. NOT
Solution: 1 XOR 1 = 0, 0 XOR 1 = 1, note that NOT inverts all the bits, while XOR toggles only a specified bit.
Q: Which of the following is not an advantage of bit array?
A. Exploit bit level parallelism
B. Maximal use of data cache
C. Can be stored and manipulated in the register set for long periods of time
D. Accessing Individual Elements is easy
Solution: Individual Elements are difficult to access and can’t be accessed in some programming languages. If random access is more common than sequential access, they have to be compressed to byte/word array. Exploit Bit parallelism, Maximal use of data cache and storage and manipulation for longer time in register set are all advantages of bit array.
Q: Which of the following is not a disadvantage of bit array?
A. Without compression, they might become sparse
B. Accessing individual bits is expensive
C. Compressing bit array to byte/word array, the machine also has to support byte/word addressing
D. Storing and Manipulating in the register set for long periods of time
Solution: Bit arrays allow small arrays of bits to be stored and manipulated in the register set for long periods of time with no memory accesses because of their ability to exploit bit-level parallelism, limit memory access, and maximally use the data cache, they often outperform many other data structures on practical data sets. This is an advantage of bit array. The rest are all disadvantages of bit array.
Q: Which of the following is/are not applications of bit arrays?
A. Used by the Linux kernel
B. For the allocation of memory pages
C. Bloom filter
D. Implementation of Vectors and Matrices
Solution: Normal Arrays are used to implement vectors and matrices. Bit arrays have no prominent role. Remaining all are applications of Bit Arrays.
Q: Which class in Java can be used to represent bit array?
A. BitSet
B. BitVector
C. BitArray
D. BitStream
Solution: The BitSet class creates a special type of array that can hold bit values.
Q: Which of the following bitwise operator will you use to invert all the bits in a bit array?
A. OR
B. NOT
C. XOR
D. NAND
Solution: NOT operation is used to invert all the bits stored in a bit array.
Eg: NOT (10110010) = 01001101.
Q: Which one of the following operations returns the first occurrence of bit 1 in bit arrays?
A. Find First Zero
B. Find First One
C. Counting lead Zeroes
D. Counting lead One
Solution: Find First One operation returns the first occurrence of bit 1 in the bit array. Find First Zero operation returns the first occurrence of bit 0 in the bit array. If the most significant bit in bit array is 1, then count lead zeroes operation returns the number of zeroes present before the most significant bit. If the most significant bit in bit array is 0, then the count lead one returns the number of ones present before the most significant bit.

You Have Score    /10